#example6_7_subplot2grid_ravel.py
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

open_price,high_price,low_price,close_price=np.loadtxt('stock.csv',
            delimiter=',', usecols=(1,2,3,4),unpack=True,skiprows=1)

x= np.arange(len(open_price))
prices = [open_price,high_price,low_price,close_price]
colors = ["red","blue","green","black"]
linestyles = ["solid","dashed","dashdot","dotted"]
labels=["开盘价","最高价","最低价","收盘价"]

plt.rcParams['font.sans-serif']=['SimHei']

# 创建图像
fig=plt.figure(figsize=(11,7))   #设置图像大小
# 用列表生成式展开子图
axes=[plt.subplot2grid((2, 2), (i, j), fig=fig) for i in range(2) 
                                                  for j in range(2)]

# in 后面的换行符 \ 不能省略
for ax,price,color,linestyle,label in \
          zip(axes,prices,colors,linestyles,labels):
    ax.plot(x,price,color=color,linestyle=linestyle)
    #选择当前子图
    plt.sca(ax)
    # 设置刻度字体大小
    plt.xticks(fontsize=15)
    plt.yticks(fontsize=15)    
    plt.title(label,fontsize=15) 
    # 为每个子图增加横纵轴标的标签
    plt.xlabel("时间顺序",fontsize=15)
    plt.ylabel(label,fontsize=15)
    
#调整子图间距
plt.subplots_adjust(wspace=0.2, hspace=0.5)
plt.show()

